package com.mc.algorithm;
import java.util.Stack;
import java.util.Iterator;
public class TwentyFive {
	private static Integer left;
	private static Integer right;
	private static int sum = 0;
	private static Stack<Integer> stack = new Stack<Integer>();
	public static void find(Node node, int key){
		sum+=node.value;
		stack.push(node.value);
		if(node.left==null&&node.right==null&&sum==key){
			
			Iterator<Integer> iter = stack.iterator();
			while(iter.hasNext())
				System.out.println(iter.next());
		}
		
		if(node.left!=null)
			find(node.left,key);
		if(node.right!=null)
			find(node.right,key);
		sum-=node.value;
		stack.pop();
	}
	public static boolean isBanlanced(Node node,Integer dep){
		if(node==null){
			dep = 0;
			return true;
		}		
		if(isBanlanced(node.left,left)&&isBanlanced(node.right, right)){
			int diff = left-right;
			if(diff<=1&&diff>=-1){
				dep = Math.max(left, right)+1;
				return true;
			}
		}
		return false;
	}
	static class Node{
		Node left;
		Node right;
		int value;
		public Node(int value){
			this.value = value;
		}

	}
	public static void main(String[] args){
		Node n1 = new Node(1);
		Node n2 = new Node(2);
		Node n3 = new Node(3);
		n1.left = n2;
		n1.right = n3;
		TwentyFive.isBanlanced(n1, new Integer(0));
//		TwentyFive.find(n1, 4);
	}
}	
